package com.ruoyi.apiserver.services;

import com.ruoyi.apiserver.config.ReportGenerationMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ReportGenerationProducerService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送报告生成请求消息
     * @param outTradeNo 订单号
     * @param userId 用户ID
     */
    public void sendReportGenerationRequest(String outTradeNo, Long userId) {
        // 创建消息内容
        Map<String, Object> message = new HashMap<>();
        message.put("outTradeNo", outTradeNo);
        message.put("userId", userId);
        message.put("timestamp", System.currentTimeMillis());
        
        // 发送消息到报告生成队列
        rabbitTemplate.convertAndSend(
            ReportGenerationMQConfig.REPORT_GENERATION_EXCHANGE,
            ReportGenerationMQConfig.REPORT_GENERATION_ROUTING_KEY,
            message
        );
    }
    
    /**
     * 发送报告生成请求消息（重载方法）
     * @param outTradeNo 订单号
     * @param userId 用户ID
     * @param extraData 额外数据
     */
    public void sendReportGenerationRequest(String outTradeNo, Long userId, Map<String, Object> extraData) {
        // 创建消息内容
        Map<String, Object> message = new HashMap<>();
        message.put("outTradeNo", outTradeNo);
        message.put("userId", userId);
        message.put("timestamp", System.currentTimeMillis());
        
        // 添加额外数据
        if (extraData != null) {
            message.putAll(extraData);
        }
        
        // 发送消息到报告生成队列
        rabbitTemplate.convertAndSend(
            ReportGenerationMQConfig.REPORT_GENERATION_EXCHANGE,
            ReportGenerationMQConfig.REPORT_GENERATION_ROUTING_KEY,
            message
        );
    }
}